package com.sky.demo01;

/**
 * 目标：演示原子性问题
 * 1. 定义一个共享变量number
 * 2. 对number进行1000的++操作
 * 3. 使用5个线程来进行
 */
public class Test02Atomicity {

    private static int number = 0;

    public static void main(String[] args) throws InterruptedException {

        Runnable runnable = () -> {
            for (int i = 0; i < 1000; i++) {
                number++;
            }
        };


        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(runnable);
            thread.start();
        }

        Thread.sleep(2000);
        System.out.println("number = " + number);
    }
}
